package com.xuecheng.content.controller;

import com.xuecheng.api.content.TeachplanMediaApi;
import com.xuecheng.api.content.model.dto.TeachplanMediaDTO;
import com.xuecheng.api.content.model.vo.TeachplanMediaVO;
import com.xuecheng.common.domain.response.RestResponse;
import com.xuecheng.common.util.SecurityUtil;
import com.xuecheng.content.service.TeachplanMediaService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author itcast
 */
@Slf4j
@RestController
public class TeachplanMediaController implements TeachplanMediaApi {

    @Autowired
    private TeachplanMediaService  teachplanMediaService;

    //content/TeachplanMedia/{mediaId}
    @GetMapping("TeachplanMedia/{mediaId}")
    public RestResponse<Integer> queryTeachPlanMedia(@PathVariable Long mediaId) {
        Integer teachPlanMedia = teachplanMediaService.getTeachPlanMedia(mediaId);
        RestResponse<Integer> success = RestResponse.success(teachPlanMedia);
        return success;
    }

    @PostMapping("teachplan/media/association")
    public TeachplanMediaDTO getTeachPlanMediaDTO(@RequestBody TeachplanMediaVO teachMediaVO) {

        Long companyId = SecurityUtil.getCompanyId();

        TeachplanMediaDTO teachplanMediaDTO = new TeachplanMediaDTO();
        teachplanMediaDTO.setMediaId(teachMediaVO.getMediaId());
        teachplanMediaDTO.setTeachplanId(teachMediaVO.getTeachplanId());

        TeachplanMediaDTO teachMediaDTO = teachplanMediaService.getTeachMediaDTO(teachplanMediaDTO, companyId);
        return teachMediaDTO;
    }
}
